package org.pz.mq.demo;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.retry.MessageRecoverer;
import org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 重试后失败的处理
 * */
@Configuration
@Slf4j
public class RabbitMqRecoverConfig {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 重试几次后，也失败了的消息处理
     * 感觉这个似乎没什么用，因为所有处理失败的消息都走这里，而且也没有消息参数啥的
     */
    @Bean
    public MessageRecoverer messageRecoverer(){
        return new RepublishMessageRecoverer(rabbitTemplate, MqDemoConfig.retry_exchange, MqDemoConfig.retry_failure_routeKey);
    }
}
